students = [
  [3,"Jack",12],
  [2,"James",13],
  [1,"Jodan",11],
  [4,"Dick",12],
]
print("学号降序",sorted(students,key=(lambda x:x[0]),reverse=True))
print("学号升序",sorted(students,key=(lambda x:x[0]),reverse=False))
print("学号升序",sorted(students,key=(lambda x:x[0])))
print("年龄、姓名升序",sorted(students,key=(lambda x:[x[2],x[1]])))
print("年龄、姓名降序",sorted(students,key=(lambda x:[x[2],x[1]]),reverse=True))


# 实现年龄升序，姓名降序 有点复杂，先放一放
from operator import itemgetter
# 先按年龄升序，再按姓名降序
sorted_students = sorted( students, key=itemgetter(2,1)) # 按年龄升序，按姓名升序
# 对同一年龄组内按姓名降序排序
from itertools import groupby

final_sorted_students = []
for age, group in groupby(sorted_students, key=itemgetter(2)):
    group_list = list(group)
    final_sorted_students.extend(sorted(group_list, key=(lambda x:x[1]), reverse=True))

print("年龄升序，姓名降序", final_sorted_students)